(function () {
    function AlertFaqUI() {
        AlertFaqUI.super(this);
        this.mousePosX = null;
        this.faqCurIndex = 0;
        this.faqTotalPage = 0;

        var res = [
            {img : "res/alert/alert_faq/faq_1.png"},
            {img : "res/alert/alert_faq/faq_2.png"},
            {img : "res/alert/alert_faq/faq_3.png"},
            {img : "res/alert/alert_faq/faq_4.png"}
        ];
        this.resConfig = [
            {width : 492, height : 629, x : 40, centerY : 0},
            {width : 526, height : 667, x : 40, centerY : 0},
            {width : 496, height : 525, x : 40, centerY : 0},
            {width : 609, height : 788, x : 5,  centerY : 25}
        ];

        this.faqContent.array = res;
        this.faqTotalPage = this.faqContent.totalPage;
        this.bindEvent();
    }
    Laya.class(AlertFaqUI, "ui.Alert.Faq", ui.Alert.FaqUI);

    var _proto = AlertFaqUI.prototype;
    
    _proto.bindEvent = function () {
        this.btnSelect.selectHandler = new Laya.Handler(this, function (index) {
            this.faqCurIndex = index;
            this.faqContent.tweenTo(index, 300);
        });
        
        this.btnSkip.on(Laya.Event.CLICK, this, function () {
            this.close();
            
            if(!Arena.UserLogged){
                location.href = Arena.LoginUrl;
                return;
            }
            
            viewer.publish("loader.load", "room");
        });

        this.faqContent.renderHandler = new Laya.Handler(this, function (item, index) {
            if(index >= this.resConfig.length){return;}
            var img = item.getChildByName("img");
            
            img.width = this.resConfig[index].width;
            img.height = this.resConfig[index].height;
            img.x = this.resConfig[index].x;
            img.centerY = this.resConfig[index].centerY;
        });

        this.faqWrap.on(Laya.Event.MOUSE_DOWN, this, function (e) {
            this.mousePosX = e.stageX;
        });

        this.faqWrap.on(Laya.Event.MOUSE_UP, this, function (e) {
            var diff = this.mousePosX - e.stageX;

            if(diff > 50){
                this.faqCurIndex += 1;
                if(this.faqCurIndex >= this.faqTotalPage){
                    this.faqCurIndex = this.faqTotalPage - 1;
                }
            }else if(diff < -50){
                this.faqCurIndex -= 1;
                if(this.faqCurIndex < 0){
                    this.faqCurIndex = 0;
                }
            }

            this.faqContent.tweenTo(this.faqCurIndex, 300);
            this.btnSelect.selectedIndex = this.faqCurIndex;
        });
    }

    _proto.display = function () {

        this.popup();
    }
})();